/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.core.action.transaction;

import java.util.Date;
import java.util.Map;
import org.grayrabbit.web.struts2.GenericAction;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.grayrabbit.pay.core.model.results.GenericsResult;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.grayrabbit.pay.core.model.pages.PageList;
import org.grayrabbit.pay.core.model.entity.system.AppSystem;
import org.grayrabbit.pay.core.model.entity.system.TradeTerminal;
import org.grayrabbit.pay.core.model.entity.transaction.TradeHistory;
import org.grayrabbit.pay.core.model.enums.TradeEnum;
import org.grayrabbit.pay.core.biz.manager.system.AppSystemManager;
import org.grayrabbit.pay.core.biz.manager.system.TradeTerminalManager;
import org.grayrabbit.pay.core.biz.manager.transaction.TradeHistoryManager;

/**
 * 
 * 
 * @author liyd
 * @version $Id: TradeHistoryAction.java, v 0.1 Fri Jun 01 11:16:04 CST 2012
 *          liyd Exp $
 */
@Results({
          @Result(name = GenericAction.RELOAD, location = "transaction/trade_history_list", type = "redirectAction"),
          @Result(name = GenericAction.INPUT, location = "transaction/trade_history-input.vm"),
          @Result(name = GenericAction.LIST, location = "transaction/trade_history-list.vm") })
@InterceptorRefs({ @InterceptorRef(value = "token", params = { "includeMethods", "save" }),
                  @InterceptorRef("login"), @InterceptorRef("defaultStack") })
public class TradeHistoryAction extends GenericAction {

    /** serialVersionUID */
    private static final long          serialVersionUID = 6745626727742850209L;

    /** 业务对象manager接口 */
    @Autowired
    private TradeHistoryManager        tradeHistoryManager;

    @Autowired
    private AppSystemManager           appSystemManager;

    @Autowired
    private TradeTerminalManager       tradeTerminalManager;

    /** 业务实体对象 */
    private TradeHistory               tradeHistory     = new TradeHistory();
    private Date                       startDate;
    private Date                       endDate;
    /** 业务实体对象列表 */
    private PageList<TradeHistory>     tradeHistoryList;
    private Map<String, AppSystem>     appMap;

    private Map<String, TradeTerminal> terminalMap;

    /**
     * 查询列表 访问URL /trade_history_list.action
     * 
     * @return
     */
    @Action(value = "trade_history_list")
    public String list() {

        GenericsResult<PageList<TradeHistory>> result = tradeHistoryManager.queryPageList(
            tradeHistory, startDate, endDate);
        GenericsResult<Map<String, AppSystem>> appResult = appSystemManager.findAllMap();
        GenericsResult<Map<String, TradeTerminal>> terminalResult = tradeTerminalManager
            .findAllMap();

        if (!result.isSuccess()) {
            this.addActionError(result.getResultMsg());
        }
        if (!appResult.isSuccess()) {
            this.addActionError(appResult.getResultMsg());
        }
        if (!terminalResult.isSuccess()) {
            this.addActionError(terminalResult.getResultMsg());
        }
        terminalMap = terminalResult.getResultData();
        appMap = appResult.getResultData();
        tradeHistoryList = result.getResultData();
        return LIST;
    }

    /**
     * Getter method for property <tt>tradeHistory</tt>.
     * 
     * @return property value of tradeHistory
     */
    public TradeHistory getTradeHistory() {
        return tradeHistory;
    }

    /**
     * Setter method for property <tt>tradeHistory</tt>.
     * 
     * @param tradeHistory
     *            value to be assigned to property tradeHistory
     */
    public void setTradeHistory(TradeHistory tradeHistory) {
        this.tradeHistory = tradeHistory;
    }

    /**
     * Getter method for property <tt>tradeHistoryList</tt>.
     * 
     * @return property value of tradeHistoryList
     */
    public PageList<TradeHistory> getTradeHistoryList() {
        return tradeHistoryList;
    }

    /**
     * Setter method for property <tt>tradeHistoryList</tt>.
     * 
     * @param districtList
     *            value to be assigned to property tradeHistoryList
     */
    public void setTradeHistoryList(PageList<TradeHistory> tradeHistoryList) {
        this.tradeHistoryList = tradeHistoryList;
    }

    public Map<String, TradeTerminal> getTerminalMap() {
        return terminalMap;
    }

    public void setTerminalMap(Map<String, TradeTerminal> terminalMap) {
        this.terminalMap = terminalMap;
    }

    public Map<String, AppSystem> getAppMap() {
        return appMap;
    }

    public void setAppMap(Map<String, AppSystem> appMap) {
        this.appMap = appMap;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public TradeEnum[] getTradeEnums() {
        return TradeEnum.values();
    }

}
